/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022.
 * Description: hkids kernel function control interface.
 * Author: weiyuchen
 * Create: 2022-09-07
 */

#include <linux/hkids/hkids.h>
#include <linux/errno.h>
#include <linux/types.h>

#ifdef CONFIG_HKIDS_CHK_CFI_EXCEPTION
static bool hkids_chk_cfi_exception;

void enable_hkids_chk_cfi_exception(bool value)
{
	hkids_chk_cfi_exception = value;
}
EXPORT_SYMBOL_NS(enable_hkids_chk_cfi_exception, HW_RTOS_NS);

bool is_hkids_chk_cfi_exception_enabled(void)
{
	return hkids_chk_cfi_exception;
}
EXPORT_SYMBOL_NS(is_hkids_chk_cfi_exception_enabled, HW_RTOS_NS);
#endif

#ifdef CONFIG_HKIDS_CHK_KO_SIG
static bool hkids_chk_ko_sig;

void enable_hkids_chk_ko_sig(bool value)
{
	hkids_chk_ko_sig = value;
}
EXPORT_SYMBOL_NS(enable_hkids_chk_ko_sig, HW_RTOS_NS);

bool is_hkids_chk_ko_sig_enabled(void)
{
	return hkids_chk_ko_sig;
}
EXPORT_SYMBOL_NS(is_hkids_chk_ko_sig_enabled, HW_RTOS_NS);
#endif

#ifdef CONFIG_HKIDS_CHK_MAC_VIOLATION
static unsigned int hkids_chk_mac_interval;

int set_chk_mac_interval(unsigned int value)
{
	if (value == CHK_MAC_VIOLATION_DISABLED ||
	   value == CHK_MAC_VIOLATION_NO_SPEED_LIMIT ||
	   (value >= CHK_MAC_VIOLATION_MIN_SPEED_LIMIT &&
	   value <= CHK_MAC_VIOLATION_MAX_SPEED_LIMIT)) {
		hkids_chk_mac_interval = value;
		return 0;
	}
	return -EINVAL;
}
EXPORT_SYMBOL_NS(set_chk_mac_interval, HW_RTOS_NS);

unsigned int get_chk_mac_interval(void)
{
	return hkids_chk_mac_interval;
}
EXPORT_SYMBOL_NS(get_chk_mac_interval, HW_RTOS_NS);
#endif
